<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/21
 * Time: 14:17
 */

namespace app\common\model;


use think\Model;

/**
 * Class TypeAttr
 * @package app\common\model
 * 类型属性模板
 */
class TypeAttr extends Model
{ //连接数据库
    protected $table= 'shop_type-attribute';
    protected $pk= 'taid';
    //类型属性添加
    public function add($data){
        $taid=input('param.taid');
        if(isset($taid)){
            //编辑
            $res = $this->validate(true)->save($data,['taid' => $taid]);
            if(false === $res){
                // 验证失败 输出错误信息
                return ['valid'=>0,'msg'=>'修改失败'];
            }else{

                return ['valid'=>1,'msg'=>'修改成功'];
            }
        }else{
        //添加
        $res=$this->validate(true)->save($data);
        if(false == $res){
            return['valid'=>0,'msg'=>$this->getError()];
        }else{
            return['valid'=>1,'msg'=>'添加成功！'];
        }
    }
    }
    //删除
    public function del($taid){
        $res =db('type-attribute')->delete($taid);
        if ($res){
            return ['valid'=>1,'msg'=>'删除成功'];
        }else{
            return ['valid'=>0,'msg'=>'删除失败'];
        }
    }
}